package com.his.his_system.controller.DruginventoryController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.his.his_system.controller.VisitController.YxyTodo;
import com.his.his_system.domain.DzmHisSupplier;
import com.his.his_system.service.DzmHisSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 供应商维护
 */
@RestController
@RequestMapping("/api/")
public class DzmHisSupplierContller {
    @Autowired
    private DzmHisSupplierService dzmHisSupplierService;

    @Resource
    private YxyTodo yxyTodo;

    /**
     * 页面显示
     * @return
     */
    @GetMapping(value = "Suoolierxianshi")
    public List<DzmHisSupplier>xianshi(){
        return dzmHisSupplierService.xianshi();
    }
    /**
     * 添加供应商
     */
    @PostMapping(value = "Suppliertianjia")
    public boolean tianjia( DzmHisSupplier dzmHisSupplier){
        System.out.println(dzmHisSupplier);
        dzmHisSupplier.setCreateTime((int)(System.currentTimeMillis()/1000));
        dzmHisSupplier.setHospitalId(yxyTodo.getHospitalid());
        return dzmHisSupplierService.save(dzmHisSupplier);
    }
    /**
     * 查询供应商联系人
     */
    @GetMapping(value = "Supplierchaxun")
    public  List<DzmHisSupplier>chaxun(String contactName){
        System.out.println(contactName);
        QueryWrapper<DzmHisSupplier>qu=new QueryWrapper<>();
    qu.like("contact_name",contactName);
    return dzmHisSupplierService.list(qu);
    }
    /**
     * 供应商删除
     */
    @PostMapping(value = "Suppliershanchu")
    public boolean sc(Long sid) {
    return dzmHisSupplierService.removeById(sid);
    }
    /**
     * 供应商修改
     */
    @PostMapping(value = "Supplierxiugai")
    public Object xiugai(String sid, String supplierName,String address,String contactName,
                         String contactTelephone,String contactMobile,
                         String bankAccount,String  createTime){
        Long i=null;
        try {
            SimpleDateFormat sim = new SimpleDateFormat("yyyy/MM/dd");
             i = (sim.parse(createTime).getTime())/1000;
        }catch (Exception e){
            System.out.println("日期格式异常");
        }
        UpdateWrapper<DzmHisSupplier> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("sid",sid);
        DzmHisSupplier d=new DzmHisSupplier();
        d.setSupplierName(supplierName);
        d.setAddress(address);
        d.setContactName(contactName);
        d.setContactTelephone(contactTelephone);
        d.setContactMobile(contactMobile);
        d.setBankAccount(bankAccount);
        d.setCreateTime(i);
        return dzmHisSupplierService.update(d,updateWrapper);
    }
}
